import struct
import ctypes
import binascii

class quoteStruct():
    def __init__(self):
        """qStruct is the structure format for a quote message
        symbol = 4s (four length string)
        side = h (short Int)
        size = int
        price = float """
        self.qStruct = struct.Struct('!5shIf')
        self.buffSize = self.qStruct.size
        self.getBuffSize()
        self.buffer = None
    
    def getBuffSize (self):
        return self.buffSize
    
    def bufferValues(self, values):
        if len(values) != 4:
            return "error"
        else:         
            self.buffer = ctypes.create_string_buffer(self.qStruct.size)   
            self.qStruct.pack_into(self.buffer, 0, *values)
            #return self.buffer
            
    def getValues(self):
        if self.buffer == None:
            return "Buffer Empty"
            
        else:
            return self.qStruct.unpack_from(self.buffer)
            
            
class orderStruct():
    def __init__(self):
        """qStruct is the structure format for a quote message
        user = int
        symbol = 4s (four length string)
        side = c (single char)
        size = int
        price = float """
        self.oStruct = struct.Struct('!I5shIf')
        self.buffSize = self.oStruct.size
        self.buffer = None
        
    def getBuffSize (self):
        return self.buffSize
    
    def bufferValues(self, values):
        if len(values) != 5:
            return "error"
        else:         
            self.buffer = ctypes.create_string_buffer(self.oStruct.size)   
            self.oStruct.pack_into(self.buffer, 0, *values)
            #return self.buffer
            
    def getValues(self):
        if self.buffer == None:
            return "Buffer Empty"
            
        else:
            return self.oStruct.unpack_from(self.buffer)


class snapshotStruct():
    def __init__(self):
        """sStruct is the structure format for a quote message
        symbol = 4s (four length string)
        bid1 = float / bSize1 = int
        bid2 = float / bSize2 = int
        bid3 = float / bSize3 = int
        bid4 = float / bSize4 = int
        bid5 = float / bSize5 = int
        
        ask1 = float / aSize1 = int
        ask2 = float / aSize2 = int
        ask3 = float / aSize3 = int
        ask4 = float / aSize4 = int
        ask5 = float / aSize5 = int
        """
        self.sStruct = struct.Struct('!fIfIfIfIfIfIfIfIfIfI')
        self.buffSize = self.sStruct.size
        self.buffer = None
        
    def getBuffSize (self):
        return self.buffSize
            
    def bufferValues(self, values):
        if len(values) != 20:
            return "error"
        else:         
            self.buffer = ctypes.create_string_buffer(self.sStruct.size)   
            self.sStruct.pack_into(self.buffer, 0, *values)
            
            
    def getValues(self):
        if self.buffer == None:
            return "Buffer Empty"
            
        else:
            return self.sStruct.unpack_from(self.buffer, 0)

        
        